var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/WFNoticeUserSelect.tsx
var WFNoticeUserSelect_exports = {};
__export(WFNoticeUserSelect_exports, {
  WFNoticeUserSelect: () => WFNoticeUserSelect
});
module.exports = __toCommonJS(WFNoticeUserSelect_exports);
var import_react = __toESM(require("react"));
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_util2 = require("./util");
var defaultPagination = { showQuickJumper: false, align: "left" };
var tableProps = {
  checkbox: true,
  rowSelected: true,
  headerHeight: 32,
  rowHeight: 30,
  style: { border: "1px solid var(--border-color-split, #f0f0f0)", borderTop: 0 }
};
var columnProps = {
  sortable: false,
  resizable: false,
  columnSort: false,
  tooltip: true
};
var WFNoticeUserSelect = (0, import_util.compHoc)(({ outRef }) => {
  const [data, setData] = (0, import_react.useState)([]);
  const openUserSelectWin = (0, import_util.useRefCallback)(async () => {
    await (0, import_util2.wfModal)({
      title: import_util2.NGLang.userSelectWinTitle,
      width: 760,
      content: /* @__PURE__ */ import_react.default.createElement(UserSelectWin, { lastSelectData: data, callBack: setData }),
      footerLeft: /* @__PURE__ */ import_react.default.createElement("div", { id: "paginationContainer", style: { flex: 1, width: 0, marginRight: 80 } })
    });
  });
  (0, import_react.useEffect)(() => {
    outRef.current.getValue = () => data;
  }, [data]);
  const showText = (0, import_react.useMemo)(() => {
    return data.map((d) => d.userName).join();
  }, [data]);
  return /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Tooltip, { title: showText, mouseEnterDelay: 0.5 }, /* @__PURE__ */ import_react.default.createElement(import_baseComponent.InputTrigger, { ref: outRef, value: showText, editable: false, onTrigger: openUserSelectWin }));
});
var tabTitle = (title) => /* @__PURE__ */ import_react.default.createElement("span", { style: { padding: "0 6px" } }, title);
function UserSelectWin({ lastSelectData, callBack }) {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const [searchValue, setSearchValue] = (0, import_react.useState)("");
  const [activeKey, setActiveKey] = (0, import_react.useState)("1");
  const columns = (0, import_react.useMemo)(() => {
    return [
      {
        ...columnProps,
        header: import_util2.NGLang.userNo,
        dataIndex: "userNo"
      },
      {
        ...columnProps,
        header: import_util2.NGLang.userName,
        dataIndex: "userName"
      }
    ];
  }, []);
  const getActiveTable = (0, import_util.useRefCallback)(() => {
    return import_util.iup.getCmp(`WfTable_${activeKey}`).getApi();
  });
  const getResultTable = (0, import_util.useRefCallback)(() => {
    return import_util.iup.getCmp(`resultWfTable`).getApi();
  });
  const toResult = (0, import_util.useRefCallback)((selectedData) => {
    const resultTable = getResultTable();
    const selected = [];
    const resultKeys = resultTable.getRows().map((r) => r.userId);
    selectedData.forEach((sd) => {
      if (!resultKeys.includes(sd.userId)) {
        selected.push(resultTable.copyRow(sd));
      }
    });
    resultTable.addRows(selected);
  });
  const toRemove = (0, import_util.useRefCallback)((indexes) => {
    if (indexes === void 0) {
      getResultTable().setDataSource([]);
    } else {
      getResultTable().deleteRows(indexes);
    }
  });
  const getTabContent = (0, import_util.useRefCallback)((tabKey) => {
    if (tabKey === "1") {
      return /* @__PURE__ */ import_react.default.createElement(OrgUserTable, { activeKey, columns, searchValue, toResult });
    }
    return /* @__PURE__ */ import_react.default.createElement(FlowUserTable, { activeKey, columns, searchValue, toResult });
  });
  const onRow = (0, import_util.useRefCallback)((rowIndex) => {
    return {
      onDoubleClick() {
        toRemove(rowIndex);
      }
    };
  });
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeOkHandler: async () => {
        var _a;
        const selectedData = getResultTable().getRows();
        if (selectedData.length === 0) {
          await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.hasNoSelectData);
          return;
        }
        callBack == null ? void 0 : callBack(selectedData);
        (_a = mCtx.ins) == null ? void 0 : _a.destroy();
      }
    });
  }, []);
  const tabs = [
    { value: "1", label: import_util2.NGLang.allUsers },
    { value: "2", label: import_util2.NGLang.flowUser }
  ];
  return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, { direction: "row", style: { height: 440, padding: "0 5px" } }, /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Tabs,
    {
      className: "fit-height ng-compact-tab",
      size: "small",
      tabBarGutter: 5,
      activeKey,
      onChange: setActiveKey,
      tabBarExtraContent: /* @__PURE__ */ import_react.default.createElement(import_baseComponent.Search, { allowClear: true, placeholder: import_util2.NGLang.seachEmptyText, size: "small", onSearch: setSearchValue })
    },
    tabs.map((tab) => /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Tabs.Option, { tab: tabTitle(tab.label), key: tab.value, children: getTabContent(tab.value) }))
  )), /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.BaseHelp.MultipleButtons,
    {
      addResult: toResult,
      removeResult: toRemove,
      getResultTable,
      getActiveTable
    }
  ), /* @__PURE__ */ import_react.default.createElement("div", { style: { width: 200, paddingTop: 7 } }, /* @__PURE__ */ import_react.default.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      style: { ...tableProps.style, marginTop: 0 },
      columns,
      id: "resultWfTable",
      dataSource: lastSelectData,
      onRow
    }
  )));
}
var OrgUserTable = import_react.default.memo(
  ({ activeKey, columns, searchValue, toResult }) => {
    const onRow = (0, import_util.useRefCallback)((rowIndex, table) => {
      return {
        onDoubleClick() {
          toResult == null ? void 0 : toResult([table.getRow(rowIndex)]);
        }
      };
    });
    const params = (0, import_react.useMemo)(() => {
      return { orgattr: "18", isRight: false };
    }, []);
    const defaultResponse = (0, import_util.useRefCallback)((res) => ({
      total: res.totalRows,
      record: res.Record
    }));
    const requestList = (0, import_util.useRefCallback)(async ({ pageIndex, pageSize, orgTreeSelectValue }) => {
      return await import_util.iup.request.get({
        url: "WorkFlow3/WorkFlow/GetUserList",
        data: {
          page: pageIndex - 1,
          deptid: orgTreeSelectValue,
          seachtext: searchValue,
          start: (pageIndex - 1) * pageSize,
          limit: pageSize
        }
      });
    });
    (0, import_util.useIUPEffect)(
      () => {
        import_util.iup.getCmpApi(`WfTable_${activeKey}`).query();
      },
      [searchValue],
      false
    );
    const onSelectCallback = (0, import_util.useRefCallback)((keys, nodes) => {
      import_util.iup.getCmpApi(`WfTable_${activeKey}`).setExtraParam({
        orgTreeSelectValue: nodes[0].id
      });
    });
    const onDataLoad = (0, import_util.useRefCallback)((nodes) => {
      nodes.push({
        value: "nodeptid",
        title: import_util2.NGLang.noDeptData,
        isLeaf: true,
        id: "nodeptid",
        key: "nodeptid",
        OCode: "nodeptid"
      });
      return nodes;
    });
    return /* @__PURE__ */ import_react.default.createElement(import_util.Layout, { direction: "row", style: { height: "100%" } }, /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: { width: 180, marginRight: 5, border: "1px solid var(--border-color-split, #f0f0f0)", borderTop: 0 }
      }
    ), /* @__PURE__ */ import_react.default.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ import_react.default.createElement(
      import_functionalComponent.Table,
      {
        id: `WfTable_${activeKey}`,
        ...tableProps,
        autoLoad: false,
        response: defaultResponse,
        pagination: { ...defaultPagination, targetContainer: "paginationContainer" },
        onRow,
        columns,
        request: requestList
      }
    )));
  },
  (p, n) => {
    return n.activeKey !== "1" || import_util.iup.isPropsEqual(p, n);
  }
);
var FlowUserTable = import_react.default.memo(
  ({ activeKey, columns, searchValue, toResult }) => {
    const dataSource = (0, import_react.useMemo)(() => {
      const flowUsers = [
        {
          userId: "WF$initiator",
          userNo: "WF$initiator",
          userName: import_util2.NGLang.flowStartUser
        },
        {
          userId: "WF$nextappman",
          userNo: "WF$nextappman",
          userName: import_util2.NGLang.nextAppName
        },
        {
          userId: "WF$allappman",
          userNo: "WF$allappman",
          userName: import_util2.NGLang.allFlowUser
        }
      ];
      return searchValue ? flowUsers.filter((row) => {
        var _a, _b;
        return ((_a = row.userName) == null ? void 0 : _a.indexOf(searchValue)) > -1 || ((_b = row.userNo) == null ? void 0 : _b.indexOf(searchValue)) > -1;
      }) : flowUsers;
    }, [searchValue]);
    const onRow = (0, import_util.useRefCallback)((rowIndex, table) => {
      return {
        onDoubleClick() {
          toResult == null ? void 0 : toResult([table.getRow(rowIndex)]);
        }
      };
    });
    return /* @__PURE__ */ import_react.default.createElement(import_functionalComponent.Table, { id: `WfTable_${activeKey}`, ...tableProps, onRow, columns, dataSource });
  },
  (p, n) => {
    return n.activeKey !== "2" || import_util.iup.isPropsEqual(p, n);
  }
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WFNoticeUserSelect
});
